package com.yamaha.bikedesalon.util;

import android.app.Activity;
import android.util.DisplayMetrics;
import android.view.Display;

public class DisplayUtil {
	private final static DisplayUtil instance = new DisplayUtil();

	private static Activity act;
	private final static float RELATIVE_WIDTH = 480.0f;

	private DisplayUtil() {
	}

	public static void init(final Activity activity) {
		DisplayUtil.act = activity;
	}

	public static DisplayUtil getInstance() {
		return instance;
	}

	public static int getWidth(final int width) {
		final float scale = act.getResources().getDisplayMetrics().widthPixels
				/ RELATIVE_WIDTH;

		return (int) (width * scale + 0.5f);
	}

	public static int getHeight(final int height) {
		final float scale = act.getResources().getDisplayMetrics().widthPixels
				/ RELATIVE_WIDTH;

		return (int) (height * scale + 0.5f);
	}

	public static float getFontSize(final int size) {
		final float scale = act.getResources().getDisplayMetrics().widthPixels
				/ RELATIVE_WIDTH;

		return (int) (size * scale + 0.5f);
	}

	public static Dimension getDisplaySize() {
		final Display display = act.getWindowManager().getDefaultDisplay();

		final Dimension size = new Dimension(display.getWidth(),
				display.getHeight());

		return size;
	}

	public static int getDisplayDensityDPI() {
		final DisplayMetrics metrics = new DisplayMetrics();
		act.getWindowManager().getDefaultDisplay().getMetrics(metrics);

		return metrics.densityDpi;
	}
}
